package com.sunwhite.codeidea.schedule;

import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
@EnableScheduling
public class ScheduleTest {

  Integer count = 1;

  @Scheduled(cron = "0/10 * * * * ?")
  public void scheduleTest() {
      count++;
      System.out.println("当前执行次数：" + count+",执行开始时间："+new Long((System.currentTimeMillis()/1000)).toString().substring(6)+"s");
      run();
  }

  public void run() {
    try {
        if (count % 2 == 0) {
        Thread.sleep(30000);
      }
      System.out.println("当前执行次数：" + count+",执行结束时间："+new Long((System.currentTimeMillis()/1000)).toString().substring(6)+"s");
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
  }
}
